package app.modules.infrastructure.lov.util.conversion;

import app.modules.common.annotation.ConvertFrom;
import app.modules.common.annotation.ConvertTo;
import app.modules.infrastructure.lov.dto.web.WebValueSetDTO;
import app.modules.infrastructure.lov.persistence.entity.ValueSetEO;
import cn.hutool.core.collection.CollectionUtil;
import jasmine.framework.common.util.MapperUtil;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * @author mh.z
 */
public class ValueSetConvertUtil {

    @ConvertFrom(ValueSetEO.class)
    @ConvertTo(WebValueSetDTO.class)
    public static List<WebValueSetDTO> valueSetEO2WebValueSetDTO(Collection<ValueSetEO> records) {
        if (CollectionUtil.isEmpty(records)) {
            return Collections.emptyList();
        }

        return MapperUtil.mapToList(records, WebValueSetDTO.class);
    }

    @ConvertFrom(ValueSetEO.class)
    @ConvertTo(WebValueSetDTO.class)
    public static WebValueSetDTO valueSetEO2WebValueSetDTO(ValueSetEO record) {
        if (record == null) {
            return null;
        }

        return MapperUtil.mapTo(record, WebValueSetDTO.class);
    }


}
